<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<style>
		#box{
			position: relative;
			top: 0px;
			left: 0px;
		}
	</style>
	<script>
		
		window.onload=function () {

			box = document.getElementById('box')
			btn = document.getElementById('btn')
			img = document.getElementById('img')

			is = true;

			btn.onclick= function(){
				if(is){
					btn.innerHTML ="停止";
					time = setInterval(run,5)
					is = false;
				}else{
					clearInterval(time)
					btn.innerHTML ="开始";
					is= true;
				}
			}

			left = 0;
			fanxiang = true;
			function run() {

				if(left<-250){
					fanxiang = true;
					img.src = "./gou.gif";
				}else if(left>1100){
					fanxiang = false;
					img.src = "./mao.gif";
				}

				if(fanxiang){
					left += 1;
				}else{
					left -= 1;
				}

				box.style.left = left+"px";
			}
		}

	</script>
</head>
<body>
	<button id="btn">开始</button>
	<div id="box">
		<img id="img" width="200" src="./gou.gif" alt="">
	</div>
</body>
</html>